﻿using System;
using System.ComponentModel;

namespace DataConvertLib
{
	/// <summary>
	/// Byte类型数据转换类
	/// </summary>
	// Token: 0x02000005 RID: 5
	[Description("Byte类型数据转换类")]
	public class ByteLib
	{
		/// <summary>
		/// 将字节中的某个位赋值
		/// </summary>
		/// <param name="value">原始字节</param>
		/// <param name="offset">位</param>
		/// <param name="bitValue">写入数值</param>
		/// <returns>返回字节</returns>
		// Token: 0x06000048 RID: 72 RVA: 0x0000398C File Offset: 0x00001B8C
		[Description("将字节中的某个位赋值")]
		public static byte SetbitValue(byte value, int offset, bool bitValue)
		{
            return (byte)(bitValue ?(value | (byte)Math.Pow(2.0, (double)offset)) : (value & ~(byte)Math.Pow(2.0, (double)offset)));
		}

		/// <summary>
		/// 从字节数组中截取某个字节
		/// </summary>
		/// <param name="value">字节数组</param>
		/// <param name="start">开始索引</param>
		/// <returns>返回字节</returns>
		// Token: 0x06000049 RID: 73 RVA: 0x000039CC File Offset: 0x00001BCC
		[Description("从字节数组中截取某个字节")]
		public static byte GetByteFromByteArray(byte[] value, int start)
		{
			bool flag = start > value.Length - 1;
			if (flag)
			{
				throw new ArgumentException("字节数组长度不够或开始索引太大");
			}
			return value[start];
		}

		/// <summary>
		/// 将布尔数组转换成字节数组
		/// </summary>
		/// <param name="value">布尔数组</param>
		/// <returns>字节数组</returns>
		// Token: 0x0600004A RID: 74 RVA: 0x000039F8 File Offset: 0x00001BF8
		[Description("将布尔数组转换成字节数组")]
		public static byte GetByteFromBoolArray(bool[] value)
		{
			bool flag = value.Length != 8;
			if (flag)
			{
				throw new ArgumentNullException("检查数组长度是否为8");
			}
			byte b = 0;
			for (int i = 0; i < 8; i++)
			{
				b = ByteLib.SetbitValue(b, i, value[i]);
			}
			return b;
		}
	}
}
